#ifndef AUDIOWIDGET_H
#define AUDIOWIDGET_H

#include "myaudioplayer.h"

#include <QAudioDecoder>
#include <QAudioSink>
#include <QCheckBox>
#include <QComboBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QMediaDevices>
#include <QMediaPlayer>
#include <QProgressBar>
#include <QPushButton>
#include <QString>
#include <QToolButton>
#include <QVector>
#include <QWidget>
#include "bilateralaudioplay.h"
#include "customslider.h"
#include "utils/util.h"
class audioWidget : public QWidget
{
    Q_OBJECT
public:
    explicit audioWidget(QWidget *parent = nullptr);
    ~audioWidget();

private:
    void getAvailableAudioOutPutDevice();
    void getAvailableAudioIntputDevice();
    void PlayAudio();
    void startMircroPhone();
    void addProgressBar(QVector<QProgressBar *> &probars, QHBoxLayout *HBoxLauout);
    void setCustomSlider(CustomSlider *slider, const QString &name);
    void setDiffStatusCustomSlider(CustomSlider *slider, bool enable);
    void setLabelAndBtn(QLabel *label,
                        QToolButton *btn,
                        const QString &LabelText,
                        const QString &iconUrl);
    void setComBox(QComboBox *combobox);
    void resetProgressBar(role r);
    void setPushButton(QPushButton *btn, const QString &objectName, const QString &text);
protected slots:
    void onCheckSpeakerButtonClicked(bool checked);
    void onCheckMircroPhoneButtonClicked(bool checked);
    void onSpeakerDeviceChange(int index);
    void onMircroPhoneDeviceChange(int index);
    void onAudioDataComputeComplete(float value, role r);
    void onSliderMove(int value);
    void onClearProBarVolume(role r);
    void onCheckBoxToggle(bool checked);
    void onInputSoundSliderMove(int value);
    void onAudioPlayFinished();
public slots:
    void stopSpeaker();
    void stopMircroPhone();
signals:

private:
    QComboBox *speakerDevice;
    //QVector<QAudioDevice *> outputDevicesVector;
    QPushButton *checkSpeaker;
    QPushButton *checkMircrophone;
    // int currentAudioOutputDeviceIndex;
    //QMediaPlayer *player;
    QList<QAudioDevice> outputDevices;
    QLabel *label1;
    QLabel *label2;
    QLabel *label3;
    QLabel *label4;
    QToolButton *btnLevel;
    QToolButton *btnyinliang;
    QToolButton *btnInputLevel;
    QToolButton *btnInputYinliang;
    QVBoxLayout *mainVLayout;
    QVBoxLayout *VLayout;
    QVBoxLayout *VLayout2; //这里是麦克风部分的垂直布局
    QComboBox *microphoneDevice;
    QHBoxLayout *HLayout2;
    QHBoxLayout *HLayout3;
    QVector<QProgressBar *> SpeakerProBars;
    QVector<QProgressBar *> MircroPhoneProBars;
    CustomSlider *sound;
    CustomSlider *inputSound;
    QAudioFormat format; //这是音频的格式
    MyAudioPlayer *myPlayer;
    bilateralAudioPlay *bilateralPlayer;
    QVector<QString> outputDevicesDescription;
    QVector<QString> iutputDevicesDescription;
    uint8_t chooseOutputDeviceIndex;
    uint8_t chooseItputDeviceIndex;
    float sliderValue; //这里是保存滑块的值的
    float inputSoundSliderValue;
    //bool audioPlayStart;
    QCheckBox *checkBox;
};

#endif // AUDIOWIDGET_H
